﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdApLongTransactionManager : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdApLongTransactionManager(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdApLongTransactionManager_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdApLongTransactionManager obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdApLongTransactionManager()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdApLongTransactionManager(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdApLongTransactionManager cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdApLongTransactionManager_cast(OdRxObject.getCPtr(pObj));
			OdApLongTransactionManager result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdApLongTransactionManager_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdApLongTransactionManager_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdApLongTransactionManager_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdApLongTransactionManager createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdApLongTransactionManager_createObject();
			OdApLongTransactionManager result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdApLongTransactionManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult checkOut(OdDbObjectId transId, OdDbObjectIdArray objList, OdDbObjectId toBlock, OdDbIdMapping errorMap, OdDbObjectId lockBlkRef)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_checkOut__SWIG_0(this.swigCPtr, OdDbObjectId.getCPtr(transId), OdDbObjectIdArray.getCPtr(objList), OdDbObjectId.getCPtr(toBlock), OdDbIdMapping.getCPtr(errorMap), OdDbObjectId.getCPtr(lockBlkRef));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult checkOut(OdDbObjectId transId, OdDbObjectIdArray objList, OdDbObjectId toBlock, OdDbIdMapping errorMap)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_checkOut__SWIG_1(this.swigCPtr, OdDbObjectId.getCPtr(transId), OdDbObjectIdArray.getCPtr(objList), OdDbObjectId.getCPtr(toBlock), OdDbIdMapping.getCPtr(errorMap));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult checkIn(OdDbObjectId transId, OdDbIdMapping errorMap, bool keepObjs)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_checkIn__SWIG_0(this.swigCPtr, OdDbObjectId.getCPtr(transId), OdDbIdMapping.getCPtr(errorMap), keepObjs);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult checkIn(OdDbObjectId transId, OdDbIdMapping errorMap)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_checkIn__SWIG_1(this.swigCPtr, OdDbObjectId.getCPtr(transId), OdDbIdMapping.getCPtr(errorMap));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult abortLongTransaction(OdDbObjectId transId, bool keepObjs)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_abortLongTransaction__SWIG_0(this.swigCPtr, OdDbObjectId.getCPtr(transId), keepObjs);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult abortLongTransaction(OdDbObjectId transId)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_abortLongTransaction__SWIG_1(this.swigCPtr, OdDbObjectId.getCPtr(transId));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbObjectId currentLongTransactionFor(OdDbDatabase pDb)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdApLongTransactionManager_currentLongTransactionFor(this.swigCPtr, OdDbDatabase.getCPtr(pDb));
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void addReactor(OdApLongTransactionReactor arg0)
		{
			TD_DbPINVOKE.OdApLongTransactionManager_addReactor(this.swigCPtr, OdApLongTransactionReactor.getCPtr(arg0));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void removeReactor(OdApLongTransactionReactor arg0)
		{
			TD_DbPINVOKE.OdApLongTransactionManager_removeReactor(this.swigCPtr, OdApLongTransactionReactor.getCPtr(arg0));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdResult addClassFilter(OdRxClass arg0)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdApLongTransactionManager_addClassFilter(this.swigCPtr, OdRxClass.getCPtr(arg0));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool isFiltered(OdRxClass arg0)
		{
			bool result = TD_DbPINVOKE.OdApLongTransactionManager_isFiltered(this.swigCPtr, OdRxClass.getCPtr(arg0));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
